#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int comp(void* s1, void* s2)
{
    return *((int*)s1) - *((int*)s2);
}
int** threeSum(int* nums, int numsSize, int* returnSize, int** returnColumnSizes)
{
    qsort(nums, numsSize, sizeof(int), comp);
    int i = 0;
    int count = 0;
    int** ans = (int**)malloc(sizeof(int*) * 18000);
    if (numsSize < 3)
    {
        *returnSize = 0;
        return ans;
    }
    for (i = 0; i < numsSize - 2; i++)
    {
        int left = i + 1;
        int right = numsSize - 1;
        if (nums[i] > 0)
            break;
        else if (i > 0 && nums[i] == nums[i - 1])
            continue;
        else
        {
            while (left < right)
            {
                if (nums[i] + nums[left] + nums[right] > 0)
                {
                    right--;
                }
                else if (nums[i] + nums[left] + nums[right] < 0)
                {
                    left++;
                }
                else
                {
                    int* a = (int*)malloc(sizeof(int) * 3);
                    a[0] = nums[i];
                    a[1] = nums[left];
                    a[2] = nums[right];
                    ans[count++] = a;
                    while (left < right && nums[left] == nums[left + 1])
                        left++;
                    while (right > left && nums[right] == nums[right - 1])
                        right--;
                    left++;
                    right--;
                }
            }
        }
    }
    *returnColumnSizes = (int*)malloc(sizeof(int) * count);
    for (i = 0; i < count; i++)
    {
        (*returnColumnSizes)[i] = 3;
    }
    *returnSize = count;
    return ans;
}



//10101010
//#define Offsetof(x,y) (int)&(((x*)0)->y)
//
//struct S
//{
//	int a;
//	char b;
//	double c;
//}s;
//int main()
//{
//	int ret = Offsetof(struct S, b);
//	printf("%d", ret);
//	return 0;
//}

//#define INT_PTR int*
//typedef int* int_ptr;
//INT_PTR a, b;
//int_ptr c, d;
//int main()
//{
//	int* e, r;
//	return 0;
//}
